/* $RCSFile: PageMenu.ascx.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice/PageModules/PageMenu/PageMenu.ascx.cs $
 * $log$
 * Revision 20 2010/08/09 10:51:21  christian.surieux
 *   Added Log comment to all .aspx .ascx .master files
 * Revision 19 2010/08/09 09:43:57  christian.surieux
 *   Added Log to cs sources files
 * Revision 6 2010/08/06 19:56:26  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AddonNice.Diagnostics;
using AddonNice.Core;
using AddonNice.Helpers;
using AddonNice.Configuration;
using AddonNice.Configuration.Settings;
using AddonNice.Settings;
using AddonNice.Settings.Cache;
using AddonNice.UI.DataTypes;
using AddonNice.UI.WebControls;

using Telerik.Web.UI;

using Trace2    =   System.Diagnostics.Trace;        


namespace AddonNice.PageModules.PageMenu
{
    public class AStr
    {
        public const string PAGEMENU_NBCOLUMNS          =   "PAGEMENU_NBCOLUMNS";
        public const string PAGEMENU_LARGEIMGWIDTH      =   "PAGEMENU_LARGEIMGWIDTH";
        public const string PAGEMENU_SMALLIMGHEIGHT     =   "PAGEMENU_SMALLIMGHEIGHT";
        public const string PAGEMENU_HEIGHT             =   "PAGEMENU_HEIGHT";
        public const string PAGEMENU_RADPANELONLY       =   "PAGEMENU_RADPANELONLY";
        public const string PAGEMENU_FULLMENUS          =   "PAGEMENU_FULLMENUS";
        public const string PAGEMENU_ROOTSUBLEVELS      =   "PAGEMENU_ROOTSUBLEVELS";
        public const string PAGEMENU_SUBLEVELS          =   "PAGEMENU_SUBLEVELS";
        public const string PAGEMENU_PANELCELLPADDING   =   "PAGEMENU_PANELCELLPADDING";
        public const string PAGEMENU_PANELCELLSPACING   =   "PAGEMENU_PANELCELLSPACING";
        public const string PAGEMENU_SHOWSITEMAP        =   "PAGEMENU_SHOWSITEMAP";
    }

    /// <summary>
    /// Initializer class for PageMenu 
    /// </summary>
    public class PageMenuSI : PortalCRMModuleControlSI
    {
        public PageMenuSI(ModuleSettingsDictionary bSettings,ISettingsOwner pm) : base()
        {
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]PageMenuSI Ctor BEG.",ModuleTraceSwitch.Sw.Info);
            InitSettings(bSettings,pm);
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]PageMenuSI Ctor END.",ModuleTraceSwitch.Sw.Info);
        }
 
        public override void InitSettings(ModuleSettingsDictionary bSettings,ISettingsOwner pm)
        {             
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]PageMenuSI InitSettings BEG.",ModuleTraceSwitch.Sw.Info);
            
            base.InitSettings(bSettings,pm);

            string extgrp                           =   pm.ExtendedResourcesGroup;
   			//Custom settings
            SettingItemSpecial NbColumns            =	new SettingItemSpecial(AStr.PAGEMENU_NBCOLUMNS,new IntegerDataType());
            NbColumns.Value			                =	"3";
            NbColumns.Order                         =   10;
			NbColumns.ExtendedGroupName             =   extgrp;
            NbColumns.Description		            =	"Nb columns in page";
			NbColumns.EnglishName		            =	"Nb Columns";
            bSettings.AddSetting(NbColumns);

            SettingItemSpecial ImgWidth		        =	new SettingItemSpecial(AStr.PAGEMENU_LARGEIMGWIDTH,new UnitDataType());
			ImgWidth.Value                          =   "48px";
			ImgWidth.Order                          =   20;
			ImgWidth.ExtendedGroupName              =   extgrp;
            ImgWidth.Description		            =	"Image Width, empty being full image size";
			ImgWidth.EnglishName		            =	"Large Image Width";
            bSettings.AddSetting(ImgWidth);

            SettingItemSpecial ImgHeight	        =	new SettingItemSpecial(AStr.PAGEMENU_SMALLIMGHEIGHT,new UnitDataType());
			ImgHeight.Order                         =   25;
			ImgHeight.ExtendedGroupName             =   extgrp;
            ImgHeight.Description		            =	"Small Image Height, empty being full image size";
			ImgHeight.EnglishName		            =	"Small Image Height";
            bSettings.AddSetting(ImgHeight);

            SettingItemSpecial MenuHeight           =	new SettingItemSpecial(AStr.PAGEMENU_HEIGHT,new UnitDataType());
			MenuHeight.Order                        =   30;
			MenuHeight.ExtendedGroupName            =   extgrp;
            MenuHeight.Description		            =	"Menu Height under each main RadPanel";
			MenuHeight.EnglishName		            =	"Menu Height";
            bSettings.AddSetting(MenuHeight);
            
            SettingItemSpecial RadPanelOnly	        =	new SettingItemSpecial(AStr.PAGEMENU_RADPANELONLY,new BooleanDataType());
            RadPanelOnly.Value			            =	StStr.strFalse;
			RadPanelOnly.Order                      =   40;
			RadPanelOnly.ExtendedGroupName          =   extgrp;
            RadPanelOnly.Description		        =	"True: a sole RadPanel is used, False: a more sophisticated construct with RadMenus";
			RadPanelOnly.EnglishName		        =	"RadPanel";
            bSettings.AddSetting(RadPanelOnly);

            SettingItemSpecial FullMenus            =	new SettingItemSpecial(AStr.PAGEMENU_FULLMENUS,new BooleanDataType());
            FullMenus.Value			                =	StStr.strFalse;
			FullMenus.Order                         =   50;
			FullMenus.ExtendedGroupName             =   extgrp;
            FullMenus.Description		            =	"True: display all menus in single page, False: have new pages for child menus";
			FullMenus.EnglishName		            =	"All Menus";
            bSettings.AddSetting(FullMenus);
            
            SettingItemSpecial RootSubLevels        =	new SettingItemSpecial(AStr.PAGEMENU_ROOTSUBLEVELS,new IntegerDataType());
            RootSubLevels.Value			            =	"0";
			RootSubLevels.Order                     =   60;
			RootSubLevels.ExtendedGroupName         =   extgrp;
            RootSubLevels.Description		        =	"Root Menu Depth, defaults to zero ";
			RootSubLevels.EnglishName		        =	"Root Menu Depth";
            bSettings.AddSetting(RootSubLevels);

            SettingItemSpecial SubLevels            =	new SettingItemSpecial(AStr.PAGEMENU_SUBLEVELS,new IntegerDataType());
            SubLevels.Value			                =	"1";
			SubLevels.Order                         =   65;
			SubLevels.ExtendedGroupName             =   extgrp;
            SubLevels.Description		            =	"Menu Depth, defaults to one, -1 means no limit";
			SubLevels.EnglishName		            =	"Menu Depth";
            bSettings.AddSetting(SubLevels);

            SettingItemSpecial PanelCellPadding		=	new SettingItemSpecial(AStr.PAGEMENU_PANELCELLPADDING,new IntegerDataType());
            PanelCellPadding.Value			        =	"4";
			PanelCellPadding.Order                  =   70;
			PanelCellPadding.ExtendedGroupName      =   extgrp;
            PanelCellPadding.Description		    =	"Internal Panel cell padding";
			PanelCellPadding.EnglishName		    =	"Internal Panel cell padding";
            bSettings.AddSetting(PanelCellPadding);
            
            SettingItemSpecial PanelCellSpacing		=	new SettingItemSpecial(AStr.PAGEMENU_PANELCELLSPACING,new IntegerDataType());
            PanelCellSpacing.Value			        =	"4";
			PanelCellSpacing.Order                  =   80;
			PanelCellPadding.ExtendedGroupName      =   extgrp;
            PanelCellSpacing.Description		    =	"Internal Panel cell spacing";
			PanelCellSpacing.EnglishName		    =	"Internal Panel cell spacing";
            bSettings.AddSetting(PanelCellSpacing);

            SettingItemSpecial ShowSiteMap		    =	new SettingItemSpecial(AStr.PAGEMENU_SHOWSITEMAP,new BooleanDataType());
            ShowSiteMap.Value			            =	StStr.strTrue;
			ShowSiteMap.Order                       =   90;
			ShowSiteMap.ExtendedGroupName           =   extgrp;
            ShowSiteMap.Description		            =	"Internal Panel cell spacing";
			ShowSiteMap.EnglishName		            =	"Internal Panel cell spacing";
            bSettings.AddSetting(ShowSiteMap);

            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]PageMenuSI InitSettings END.",ModuleTraceSwitch.Sw.Info);
            
        }
    }


    public partial class PageMenu : PortalCRMModuleControl
	{
		
        /// <summary>
        /// No entity needed here
        /// </summary>
        public override bool NeedAttachedEntity
        {
            get
            {
                return false;
            }
        }

		#region General Implementation

        public override Guid GuidID 
		{
			get
			{
				return new Guid("{DBC977C6-E326-49c4-9A47-0D36B6AD9684}");
			}
		}

		#endregion

        public PageMenu()
        {
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]PageMenu Ctor Called.",ModuleTraceSwitch.Sw.Info);
        }
        
        public override string ExtendedResourcesGroup 
		{
            get
            {
       			const string extgrp                     =   "PAGEMENU";
                return extgrp;
            }
		}

        public override void InitPortalModuleControl(ModuleSettingsDictionary bSettings)
        {
            PortalModuleInitializer =   new PageMenuSI(bSettings,this);
        }


        #region Std overrides
		
        public override void Page_PreInit(object sender, EventArgs e)
        {
            // apply local parameters
            PageRadPanelMenuNavigation1.NbColumns           =   Settings[AStr.PAGEMENU_NBCOLUMNS].ToInt();
            PageRadPanelMenuNavigation1.LargeImgWidth       =   Settings[AStr.PAGEMENU_LARGEIMGWIDTH].ToUnit();
            PageRadPanelMenuNavigation1.SmallImgHeight      =   Settings[AStr.PAGEMENU_SMALLIMGHEIGHT].ToUnit();
            PageRadPanelMenuNavigation1.MenuHeight          =   Settings[AStr.PAGEMENU_HEIGHT].ToUnit();
            PageRadPanelMenuNavigation1.RadPanelOnly        =   Settings[AStr.PAGEMENU_RADPANELONLY].ToBool();
            PageRadPanelMenuNavigation1.FullMenus           =   Settings[AStr.PAGEMENU_FULLMENUS].ToBool();
            PageRadPanelMenuNavigation1.RootSubLevels       =   Settings[AStr.PAGEMENU_ROOTSUBLEVELS].ToInt();
            PageRadPanelMenuNavigation1.SubLevels           =   Settings[AStr.PAGEMENU_SUBLEVELS].ToInt();
            PageRadPanelMenuNavigation1.PanelCellPadding    =   Settings[AStr.PAGEMENU_PANELCELLPADDING].ToInt();
            PageRadPanelMenuNavigation1.PanelCellSpacing    =   Settings[AStr.PAGEMENU_PANELCELLSPACING].ToInt();
            PageRadPanelMenuNavigation1.ShowSiteMap         =   Settings[AStr.PAGEMENU_SHOWSITEMAP].ToBool();
            
            base.Page_PreInit(sender, e);
        }

        override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}

        private void InitializeComponent() 
        {
			//this.Load += new EventHandler(this.Page_Load);
		}
		#endregion
	}
}